package com.todod.common.util;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import eu.bitwalker.useragentutils.Browser;
import eu.bitwalker.useragentutils.UserAgent;
import eu.bitwalker.useragentutils.Version;

/**
 * @author gsh
 * @version 创建时间：2017-11-27 下午3:12:09
 * 
 */
public class UserAgentUtil {
	static Logger log = LoggerFactory.getLogger(UserAgentUtil.class);

	public static String getBrowser(HttpServletRequest request) {

		String info = "";
		try {
			// 获取浏览器信息
			String userAgent = request.getHeader("User-Agent");
			Browser browser = UserAgent.parseUserAgentString(userAgent).getBrowser();

			if (browser != null) {
				info += browser.getName();

				// 获取浏览器版本号
				Version version = browser.getVersion(userAgent);
				if (version != null) {
					info += "/" + version.getVersion();
				}
			}
		} catch (Exception e) {
			log.error("error", e);
		}
		return info;
	}
}
